import 'package:app/config/config.dart';
import 'package:app/provider/provider_model.dart';
import 'package:app/router/routes.dart';
import 'package:app/theme/app_theme.dart';
import 'package:app/tool/tools.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() {
  /// 配置路由开始
  FluroRouter router = FluroRouter();
  Routes.configureRoutes(router);
  NavTool.router = router;

  /// 入口
  GlobalConfig.init().then((e) => runApp(MyApp()));
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MultiProvider(
      providers: [
        ChangeNotifierProvider.value(value: ThemeModel()),
        ChangeNotifierProvider.value(value: UserModel()),
      ],
      child: Consumer2<ThemeModel, UserModel>(
          builder: (context, themeModel, userModel, child) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: AppTheme.getThemeData(themeModel.theme),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
          onGenerateRoute: NavTool.router.generator,
        );
      }),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new RaisedButton(
                child: new Text("RouterA"),
                onPressed: () {
                  NavTool.push(context, "/routerA");
                }),
            new RaisedButton(
                child: new Text("RouterB"),
                onPressed: () {
                  NavTool.push(context, "/routerB");
                }),
            new RaisedButton(
                child: new Text("图标"),
                onPressed: () {
                  NavTool.push(context, "/icon");
                }),
            Text(
              'You have clicked the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      drawer: Drawer(
        child: ListView(
          children: <Widget>[
            Container(
              height: 160,
              child: UserAccountsDrawerHeader(
                //设置用户名
                accountName: new Text('用户名'),
                //设置用户邮箱
                accountEmail: new Text('邮箱'),
                //设置当前用户的头像
                currentAccountPicture: new CircleAvatar(
                  backgroundImage: new AssetImage('images/header.png'),
                ),
                //回调事件
                onDetailsPressed: null,
              ),
            ),
            ListTile(
              leading: Icon(Icons.wifi),
              title: new Text('无线网络1'),
              subtitle: new Text('我是副标题'),
            ),
            ListTile(
              leading: Icon(Icons.wifi),
              title: new Text('无线网络2'),
              subtitle: new Text('我是副标题'),
            ),
            ListTile(
              leading: Icon(Icons.wifi),
              title: new Text('无线网络3'),
              subtitle: new Text('我是副标题'),
              onTap: () {
                print('ssss');
              },
            ),
            ListTile(
              leading: Icon(Icons.wifi),
              title: new Text('无线网络4'),
              subtitle: new Text('我是副标题'),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
